package com.zhang.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.crm.constant.Constants;
import com.zhang.crm.mapper.TClueRemarkmapper;
import com.zhang.crm.pojo.TClueRemark;
import com.zhang.crm.service.ClueRemarkService;
import com.zhang.crm.util.UserUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class ClueRemarkServiceImpl implements ClueRemarkService {

    @Resource
    private TClueRemarkmapper tClueRemarkmapper;

    @Override
    public PageInfo<TClueRemark> getRemarkList(Integer clueId, Integer current) {
        PageHelper.startPage(current, Constants.PAGE_DATA_SIZE);

        List<TClueRemark> remarkList = tClueRemarkmapper.selectByClueIdRemarkList(clueId);

        PageInfo<TClueRemark> tClueRemarkPageInfo = new PageInfo<>(remarkList);
        return tClueRemarkPageInfo;
    }


    @Transactional
    @Override
    public Boolean addClue(TClueRemark tClueRemark) {
        tClueRemark.setCreateTime(new Date());
        tClueRemark.setCreateBy(UserUtil.getUserInfo().getId());
        tClueRemark.setDeleted(0);
        int insert = tClueRemarkmapper.insert(tClueRemark);
        return insert > 0 ? true : false;
    }

    @Override
    public Boolean upDateClue(TClueRemark tClueRemark) {
        tClueRemark.setEditBy(UserUtil.getUserInfo().getId());
        tClueRemark.setEditTime(new Date());
        int i = tClueRemarkmapper.updateByPrimaryKeySelective(tClueRemark);
        return i > 0 ? true : false;
    }

    @Override
    public Boolean upDateClueDelete(Integer clueRemarkId) {
        int i = tClueRemarkmapper.upDateClueDelete(clueRemarkId);
        return null;
    }
}
